package com.zhongshan.ga.mybatis.dao;

import java.util.ArrayList;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.zhongshan.ga.mybatis.bean.AddTravelMateInfoBean;
import com.zhongshan.ga.mybatis.bean.SelectTravedlMateListInfo;
import com.zhongshan.ga.mybatis.bean.TravelMateCommentBean;
import com.zhongshan.ga.mybatis.bean.TravelMateImg;
import com.zhongshan.ga.mybatis.bean.TravelMateImgBean;
import com.zhongshan.ga.mybatis.bean.TravelMateListInfo;

/**
 * 查询结伴游信息数据接口
 * @author yanqi
 *
 */
public interface ITravelMateInfoDao {
	
	/**
	 * 根据结伴游编码查询评论数
	 * @param travelMateCode 结伴游编码
	 * @return int 评论数
	 */
	@Select("SELECT COUNT(1) FROM travelmateimg WHERE TravelMateCode = #{travelMateCode} AND IsActivity =1")
	public int selectTravelCommentCount(String travelMateCode);
	
	/**
	 * 根据结伴游编码查询参加的人数
	 * @param travelMateCode 结伴游编码
	 * @return int 人数
	 */
	@Select("SELECT COUNT(1) FROM TravelMateList WHERE TravelMateCode= #{travelMateCode} AND IsActivity =1")
	public int selectTravelMateLsitCount(String travelMateCode);
	
	/**
	 * 根据结伴游编码查询参与的人的头像
	 * @param travelMateCode 结伴游编码
	 * @return ArrayList<String>
	 */
	@Select("SELECT HeadImgUrl FROM TravelMateList a LEFT JOIN userheadimg b ON a.`PeopleSystemCode` = b.`PeopleSystemCode` WHERE a.`TravelMateCode`= #{travelMateCode} AND b.`IsActivity` = 1 GROUP BY b.`PeopleSystemCode`")
	public ArrayList<String> selectJoinPeopleImg(String travelMateCode);
	
	/**
	 * 根据用户系统编码获得用户昵称
	 * @param peopleSystemCode
	 * @return
	 */
	@Select("SELECT NickName FROM peopleinfo WHERE PeopleSystemCode = #{peopleSystemCode}")
	public String selectNickNameByPeopleSystemCode(String peopleSystemCode);
	
	/**
	 * 插入结伴游 
	 * @param addTravelMateInfoBean 结伴游信息
	 * @return
	 */
	@Insert("INSERT INTO travelmateinfo (TravelMateCode, PeopleSystemCode, TravelMateTitle, TravelMateContent, TravelTime, PublishTime, OrderNum, DepartPlace, Bourn, IsPublish, IsActivity)"
	 +" VALUES (#{travelMateCode}, #{peopleSystemCode}, #{travelMateTitle}, #{travelMateContent}, #{travelTime}, #{publishTime}, #{orderNum}, #{departPlace}, #{bourn}, #{isPublish}, #{isActivity})")
	public int addPublishTravelInfo(AddTravelMateInfoBean addTravelMateInfoBean);
	
	/**
	 * 添加结伴游图片信息
	 * @param travelMateImgBean
	 * @return
	 */
	@Insert("INSERT INTO travelmateimg (ImageName, TravelMateCode, IsActivity) VALUES (#{imageName}, #{travelMateCode}, #{isActivity})")
	public int addTravelMateImg(TravelMateImg travelMateImg);
	
	/**
	 * 根据结伴游编码查询结伴游信息
	 * @param travelMateCode
	 * @return
	 */
	@Select("SELECT ImageName FROM travelmateimg WHERE TravelMateCode = #{travelMateCode}")
	public String selectTravelMateImg(String travelMateCode);
	
	/**
	 * 根据结伴游编码和用户系统编码查询加入的情况
	 * @param travelMateCode 结伴游编码
	 * @param peopleSystemCode 用户系统编码
	 * @return
	 */
	@Select("SELECT * FROM travelmatelist WHERE TravelMateCode = #{travelMateCode} AND PeopleSystemCode = #{peopleSystemCode}")
	public TravelMateListInfo selectMatesByTravelCodeAndSystemCode(@Param("travelMateCode") String travelMateCode, @Param("peopleSystemCode") String peopleSystemCode);
	
	/**
	 * 加入成员
	 * @param travelMateListInfo
	 * @return
	 */
	@Insert("INSERT INTO travelmatelist(TravelMateCode, PeopleSystemCode, JoinTime, IsActivity) VALUES(#{travelMateCode}, #{peopleSystemCode}, #{joinTime},#{isActivity})")
	public int addTravelMateList(TravelMateListInfo travelMateListInfo);
	
	/**
	 * 加入结伴游评论内容
	 * @param travelMateCommentBean
	 * @return
	 */
	@Insert("INSERT INTO travelmatecommon(TravelMateCode, PeopleSystemCode, CommonContent, CommonTime, replyToPeople, IsActivity, isLook) VALUES(#{travelMateCode},#{peopleSystemCode},#{commonContent},#{commonTime},#{replyToPeople},1,1)")
	public int addTravelMateComment(TravelMateCommentBean travelMateCommentBean);
}
